﻿using mvcForum.Web.Attributes;
using System;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

using mvcForum.Core;
using mvcForum.Web.Extensions;
using mvcForum.Core.Configuration;

namespace mvcForum.Web.ViewModels.Create {

	public class CreateTopicViewModel : ForumViewModelBase {
		private AccessFlag flag;

		public CreateTopicViewModel() { }

		public CreateTopicViewModel(Forum forum, Int32 topicsPerPage, AdminAuthorNameSetting authorSetting)
			: base() {

			this.Type = TopicType.Regular;
			this.Forum = new ForumViewModel(forum, topicsPerPage, authorSetting);

			this.ForumId = forum.Id;
			flag = forum.GetAccess();
		}

		public bool IsModerator {
			get {
				return (this.flag & AccessFlag.Moderator) == AccessFlag.Moderator;
			}
		}

		public bool CanUpload {
			get {
				return (this.flag & AccessFlag.Upload) == AccessFlag.Upload;
			}
		}

		[Required]
		public int ForumId { get; set; }

		[Required]
		[LocalizedDisplay("mvcForum.Web.CreateTopic","Subject")]
		public String Subject { get; set; }
		[LocalizedDisplay("mvcForum.Web.CreateTopic", "Type")]
		public TopicType Type { get; set; }
		[AllowHtml]
		[Required]
		[LocalizedDisplay("mvcForum.Web.CreateTopic", "Message")]
		public String Body { get; set; }
		[LocalizedDisplay("mvcForum.Web.CreateTopic", "AttachFile")]
		public Boolean AttachFile { get; set; }

		public ForumViewModel Forum { get; set; }
	}
}